<?php
/*
Jagua - An Integrated Development Enviroment 
Copyright (C) 2007 Fernando Correa da Conceição <fernandoc@php.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/**
 * This file contains the class Error
 *
 *@package Common
 *@author Fernando Correa da Conceição <fernandoc@php.net>
 *@version 0.1
 *@link http://fernando.viaserver.com.br/jagua/
 *@since 0.1
 *@copyright 2007 Fernando Correa da Conceição
 *@license LGLP
 */

/**
 * This class manages errors
 *
 *@package Common
 */ 
class Error
{
    const FATAL = 1;
    const WARNING = 2;
    const NOTICE = 3;
    const DEBUG = 4;
    
    private $backtrace;
    
    function __constuct($message, $level = Self::WARNING, $data = "")
    {
    }
    
    /**
     * Show a message in the console 
     *
     * This is usefull to debug, it show a message and some other extra info,
     * like the funcion and where this message is(so it is easy to remove when
     * you do not need it more).
     */
    public static function debug($msg)
    {
        $arr = debug_backtrace();
        echo("\n\n**************************************************\n");
        echo("\nFile: "     . $arr[0]["file"]);
        echo("\nLine: "     . $arr[0]["line"]);
        echo("\nClass: "    . $arr[1]["class"]);
        echo("\nFunction: " . $arr[1]["function"]);
        echo("\nMessage: " . print_r($msg, true));
    }

    
    /**
     * Tell that a function is not iplemented
     *
     * When you are cerating an application sometimes you need to create a 
     * function but you do not write the code for it, so use this to tell this.
     */
    public static function NI($params = "")
    {
        $arr = debug_backtrace();
        echo("\n\n**************************************************\n");
        echo("\nFile: "     . $arr[0]["file"]);
        echo("\nLine: "     . $arr[0]["line"]);
        echo("\nClass: "    . $arr[1]["class"]);
        echo("\nFunction: " . $arr[1]["function"]);
        echo("\nMessage: "  . "This function is Not Implemented!");
    }
    
    /**
     * Show a simple backtrace to see the call order
     */
    public static function backtrace($itens = 3) {
        $arr = debug_backtrace();
        for($i = 0; $i < $itens; $i++) {
            echo("\nFile: "     . $arr[$i]["file"]);
            echo("\nLine: "     . $arr[$i]["line"]);
            echo("\nClass: "    . $arr[$i+1]["class"]);
            echo("\nFunction: " . $arr[$i+1]["function"]);
        }  
    }    
}

?>
